﻿using Calligraphy.CalligraphyData;
using Calligraphy.DataModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Group Detail Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234229

namespace Calligraphy
{
    /// <summary>
    /// A page that displays an overview of a single group, including a preview of the items
    /// within the group.
    /// </summary>
    public sealed partial class StelesDetailPage : Calligraphy.Common.LayoutAwarePage
    {
        
        public StelesDetailPage()
        {
            
            this.InitializeComponent();
            
        }


        /// <summary>
        /// Populates the page with content passed during navigation.  Any saved state is also
        /// provided when recreating a page from a prior session.
        /// </summary>
        /// <param name="navigationParameter">The parameter value passed to
        /// <see cref="Frame.Navigate(Type, Object)"/> when this page was initially requested.
        /// </param>
        /// <param name="pageState">A dictionary of state preserved by this page during an earlier
        /// session.  This will be null the first time a page is visited.</param>
        protected override void LoadState(Object navigationParameter, Dictionary<String, Object> pageState)
        {
            T_StelePaper stelePaper;
            if (pageState != null && pageState.ContainsKey("Group"))
            {
                stelePaper = (T_StelePaper)pageState["Group"];
            }
            else
            {
                stelePaper = (T_StelePaper)navigationParameter;
                StelePaperDataSource _ds = new StelePaperDataSource();
                _ds.LoadRubbings(stelePaper);
                
            }
            
            this.DefaultViewModel["Group"] = stelePaper;
            this.DefaultViewModel["Items"] = stelePaper.T_Rubbing;
            // TODO: Assign a bindable group to this.DefaultViewModel["Group"]
            // TODO: Assign a collection of bindable items to this.DefaultViewModel["Items"]
        }

        protected override void SaveState(Dictionary<string, object> pageState)
        {            
            T_StelePaper stelePaper = (T_StelePaper)this.DefaultViewModel["Group"];
            pageState.Add("Group", stelePaper);
            base.SaveState(pageState);
        }

        private void itemGridView_ItemClick(object sender, ItemClickEventArgs e)
        {
            this.Frame.Navigate(typeof(RubbingPhotoesPage), e.ClickedItem);
        }
    }
}
